import { http } from '@/utils/http'
import type { getnews, news, category ,newsItem} from '@/types/index'
import type { hotItem } from '@/types/news'

//获取分类
export const getCatrgoryAPI = () => {
  return http<category[]>({
    method: 'GET',
    url: '/news/category'
  })
}
//获取新闻
export const getNewAPI = (data: getnews) => {
  return http<news>({
    method: 'GET',
    url: '/news/info',
    data
  })
}
export const ClickFavorite = (data: { newsId: number, account: string | undefined }) => {
  return http({
    method: 'PUT',
    url: `/news/favorite?newsId=${data.newsId}&account=${data.account}`,
  })
}
export const ClickLike = (data: { newsId: number, account: string | undefined }) => {
  return http({
    method: 'PUT',
    url: `/news/like?newsId=${data.newsId}&account=${data.account}`,

  })
}
export const SearchAPI = (data: { keyword: string, page: number, pageSize: number }) => {
  return http<any>({
    url: `/news/search?keyword=${data.keyword}&page=${data.page}&pageSize=${data.pageSize}`,
    method: 'GET'
  })
}
export const hotAPI = () => {
  return http<hotItem[]>({
    url: '/news/hot',
    method: 'GET'
  })
}